﻿using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour
{
    public Vector3 offset = new Vector3(0, 10, -8);//相机相对于玩家的位置
    public Transform target;
    private Vector3 pos;
    public float speed = 2;

    void Update()
    {
        if (target == null)
            return;
        pos = target.position + offset;
        transform.position = Vector3.Lerp(this.transform.position, pos, speed * Time.deltaTime);//调整相机与玩家之间的距离
        Quaternion angel = Quaternion.LookRotation(target.position - this.transform.position);//获取旋转角度
        transform.rotation = Quaternion.Slerp(this.transform.rotation, angel, speed * Time.deltaTime);
    }
}
